package bjtu.pinet.common.pinetpacket;

import org.onlab.packet.BasePacket;

import java.io.Serializable;

/**
 * author:chushuai
 * date:2021.2.13
 */
public class HttpPacket extends BasePacket implements Serializable {
    protected String method;
    protected String Path;
    protected String Http_Version;
    protected String A_IM;
    protected String Accept;
    protected String Accept_Charset;
    protected String Accept_Datetime;
    protected String Accept_Encoding;
    protected String Accept_Language;
    protected String Access_Control_Request_Headers;
    protected String Access_Control_Request_Method;
    protected String Authorization;
    protected String Connection;
    protected String Cache_Control;
    protected String  Cookie;
    protected String DNT;
    protected String Date;
    protected String Expect;
    protected String Forwarded;
    protected String From;
    protected String Front_End_Https;
    protected String HTTP2_Settings;
    protected String Host;
    protected String If_Match;
    protected String If_Modified_Since;
    protected String If_None_Match;
    protected String If_Range;
    protected String If_Unmodified_Since;
    protected String Keep_Alive;
    protected String Max_Forwards;
    protected String Origin;
    protected String Permanent;
    protected String Pragma;
    protected String  Proxy_Authorization;
    protected String  Proxy_Connection;
    protected String Range;
    protected String Referer;
    protected String Save_Data;
    protected String  TE;
    protected String  Upgrade;
    protected String  Upgrade_Insecure_Requests;
    protected String  User_Agent;
    protected String Via;
    protected String Warning;
    protected String  X_ATT_DeviceId;
    protected String X_Correlation_ID;
    protected String X_Csrf_Token;
    protected String X_Forwarded_For;
    protected String X_Forwarded_Host;
    protected String X_Forwarded_Proto;
    protected String X_Http_Method_Override;
    protected String X_Request_ID;
    protected String X_Requested_With;
    protected String X_UIDH;
    protected String X_Wap_Profile;
    protected String  Unknown_Headers;
    public HttpPacket(String method, String path, String http_Version) {
        this.method = method;
        Path = path;
        Http_Version = http_Version;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }
    public String getPath() {
        return Path;
    }

    public void setPath(String path) {
        this.Path = path;
    }

    public String getHttp_Version() {
        return Http_Version;
    }

    public void setHttp_Version(String http_Version) {
        this.Http_Version = http_Version;
    }

    @Override
    public byte[] serialize() {
        String s = method+" " + Path + " " + Http_Version;
        byte[] bytes = s.getBytes();
        return bytes;
    }

    public static HttpPacket deserialize(byte[] bytes){
        String s = new String(bytes);
        String[] strings = s.split(" ");
        HttpPacket httpPacket = new HttpPacket(strings[0],strings[1],strings[2]);
        return httpPacket;
    }

    @Override
    public String toString() {
        return "HttpPacket{" +
                "method='" + method + '\'' +
                ", Path='" + Path + '\'' +
                ", Http_Version='" + Http_Version + '\'' +
                ", A_IM='" + A_IM + '\'' +
                ", Accept='" + Accept + '\'' +
                ", Accept_Charset='" + Accept_Charset + '\'' +
                ", Accept_Datetime='" + Accept_Datetime + '\'' +
                ", Accept_Encoding='" + Accept_Encoding + '\'' +
                ", Accept_Language='" + Accept_Language + '\'' +
                ", Access_Control_Request_Headers='" + Access_Control_Request_Headers + '\'' +
                ", Access_Control_Request_Method='" + Access_Control_Request_Method + '\'' +
                ", Authorization='" + Authorization + '\'' +
                ", Connection='" + Connection + '\'' +
                ", Cache_Control='" + Cache_Control + '\'' +
                ", Cookie='" + Cookie + '\'' +
                ", DNT='" + DNT + '\'' +
                ", Date='" + Date + '\'' +
                ", Expect='" + Expect + '\'' +
                ", Forwarded='" + Forwarded + '\'' +
                ", From='" + From + '\'' +
                ", Front_End_Https='" + Front_End_Https + '\'' +
                ", HTTP2_Settings='" + HTTP2_Settings + '\'' +
                ", Host='" + Host + '\'' +
                ", If_Match='" + If_Match + '\'' +
                ", If_Modified_Since='" + If_Modified_Since + '\'' +
                ", If_None_Match='" + If_None_Match + '\'' +
                ", If_Range='" + If_Range + '\'' +
                ", If_Unmodified_Since='" + If_Unmodified_Since + '\'' +
                ", Keep_Alive='" + Keep_Alive + '\'' +
                ", Max_Forwards='" + Max_Forwards + '\'' +
                ", Origin='" + Origin + '\'' +
                ", Permanent='" + Permanent + '\'' +
                ", Pragma='" + Pragma + '\'' +
                ", Proxy_Authorization='" + Proxy_Authorization + '\'' +
                ", Proxy_Connection='" + Proxy_Connection + '\'' +
                ", Range='" + Range + '\'' +
                ", Referer='" + Referer + '\'' +
                ", Save_Data='" + Save_Data + '\'' +
                ", TE='" + TE + '\'' +
                ", Upgrade='" + Upgrade + '\'' +
                ", Upgrade_Insecure_Requests='" + Upgrade_Insecure_Requests + '\'' +
                ", User_Agent='" + User_Agent + '\'' +
                ", Via='" + Via + '\'' +
                ", Warning='" + Warning + '\'' +
                ", X_ATT_DeviceId='" + X_ATT_DeviceId + '\'' +
                ", X_Correlation_ID='" + X_Correlation_ID + '\'' +
                ", X_Csrf_Token='" + X_Csrf_Token + '\'' +
                ", X_Forwarded_For='" + X_Forwarded_For + '\'' +
                ", X_Forwarded_Host='" + X_Forwarded_Host + '\'' +
                ", X_Forwarded_Proto='" + X_Forwarded_Proto + '\'' +
                ", X_Http_Method_Override='" + X_Http_Method_Override + '\'' +
                ", X_Request_ID='" + X_Request_ID + '\'' +
                ", X_Requested_With='" + X_Requested_With + '\'' +
                ", X_UIDH='" + X_UIDH + '\'' +
                ", X_Wap_Profile='" + X_Wap_Profile + '\'' +
                ", Unknown_Headers='" + Unknown_Headers + '\'' +
                '}';
    }
}
